package com.hrm.controller.popup;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractFormController;

import com.hrm.model.dto.code.CodeDTO;
import com.hrm.model.service.CodeService;

public class PopCodeListController extends AbstractFormController{
	private CodeService codeService;
	
	public void setCodeService(CodeService codeService) {
		this.codeService = codeService;
	}

	@Override
	protected ModelAndView processFormSubmission(HttpServletRequest request,
			HttpServletResponse arg1, Object arg2, BindException arg3)
			throws Exception {
		ModelAndView mv = new ModelAndView();
//		System.out.println("Submission---------------");

		String kind = request.getParameter("kind");
		String codeId = request.getParameter("codeId");
		String nameId = request.getParameter("nameId");

		
		mv.addObject("kind", kind);
		mv.addObject("codeId", codeId);
		mv.addObject("nameId", nameId);
		
		List list = codeService.getAllCode((CodeDTO)arg2);
		mv.addObject("list", list);
		
		mv.setViewName("popCodeList");
	
		return mv;
	}

	@Override
	protected ModelAndView showForm(HttpServletRequest request,
			HttpServletResponse arg1, BindException arg2) throws Exception {
		ModelAndView mv = new ModelAndView();
//		System.out.println("showForm--------------");
		
		String kind = request.getParameter("kind");
		String codeId = request.getParameter("codeId");
		String nameId = request.getParameter("nameId");
		
		mv.addObject("kind", kind);
		mv.addObject("codeId", codeId);
		mv.addObject("nameId", nameId);
		
		mv.setViewName("popCodeList");
		return mv;
	}

}
